/**
 @file ctc_asw_security.h

 @author  Copyright (C) 2011 Centec Networks Inc.  All rights reserved.

 @date 2010-2-4

 @version v1.0
 This module is designed to support implementation of security.
 \p
 It is including function as follows:
 \p
 \d    mac security
 \d    storm control
 \p
 The mac security will contains two parts: port security and mac limit.
 \p
 Enable or disable mac limit on a port, a vlan or system. Based on port, the function will be enabled on port by API
 ctc_asw_mac_security_set_learn_limit(). When the function enabled on port, the packet received on port will do action
 as enum ctc_maclimit_action_t defined. Based on vlan, the function will be enabled by API ctc_mac_security_set_vlan_mac_limit().
 When the function enabled on vlan, the packet with the vlan forwarding will do action as enum ctc_maclimit_action_t defined.
 any packet will do action as enum ctc_maclimit_action_t defined.
 \b
 \p
 Storm control is used to limit the rate of bridge packet include unicast and mcast. Usually, unknown unicast and mcast bridge packet rate is
 limited on edge point of network. The Module support port and vlan base storm control and total is 63 controls entry which port and vlan shares
 storm control can limit rate by bps and bps and its grain is 1kbps or pbs. Before use api set storm control limit rate, it's recommend to set global
 configure by ctc_storm_ctl_set_global_cfg().
 \S ctc_security.h:ctc_maclimit_action_t
 \S ctc_security.h:ctc_security_storm_ctl_op_t
 \S ctc_security.h:ctc_security_storm_ctl_type_t
 \S ctc_security.h:ctc_security_storm_ctl_mode_t
 \S ctc_security.h:ctc_security_learn_limit_type_t
 \S ctc_security.h:ctc_security_learn_limit_t
 \S ctc_security.h:ctc_security_stmctl_cfg_t
 \S ctc_security.h:ctc_security_stmctl_glb_cfg_t
*/

#ifndef _CTC_ASW_SECURITY_H
#define _CTC_ASW_SECURITY_H
#ifdef __cplusplus
extern "C" {
#endif

#include "ctc_security.h"
#include "ctc_l2.h"
#include "ctc_asw_common.h"

/**********************************************************************************
                      Define API function interfaces
***********************************************************************************/
/**
 @addtogroup security SECURITY
 @{
*/

/**
 @brief  Init security module

 @param[in] lchip    local chip id

 @param[in] security_global_cfg   security module global config

 @remark[TMA]
      Initialize security feature module, when init, having no need to give global configuration.
      When Initialized, port isolate function will be enabled.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_security_init(uint8 lchip, void* security_global_cfg);

/**
 @brief De-Initialize security module

 @param[in] lchip    local chip id

 @remark[TMA]  User can de-initialize the security configuration

 @return CTC_E_XXX
*/
extern int32
ctc_asw_security_deinit(uint8 lchip);

/**
 @brief Configure learn limit

 @param[in] lchip    local chip id

 @param[in] p_learn_limit    refer to ctc_security_learn_limit_t

 @remark[TMA]
       The API configure learn limit for a gport or vlan or global system.
       The learn limit type is assigned by type as enum ctc_security_learn_limit_type_t.
       \p
       type:
            \p
            CTC_SECURITY_LEARN_LIMIT_TYPE_PORT:          port based learn limit.
            \p
            CTC_SECURITY_LEARN_LIMIT_TYPE_VLAN:          vlan based learn limit.
       When the function enabled on gport, the union gport is valid.
       When the function enabled on vlan, the union vlan_id is valid.
       If learnt entries reach the number defined by limit (0 means disable learn limit).

 @return CTC_E_XXX
*/
extern int32
ctc_asw_mac_security_set_learn_limit(uint8 lchip, ctc_security_learn_limit_t* p_learn_limit);

/**
 @brief Get the configure learn limit

 @param[in] lchip    local chip id

 @param[in|out] p_learn_limit    refer to ctc_security_learn_limit_t

 @remark[TMA]
       Get info about configuration and running counter of learn limit.
 @return CTC_E_XXX
*/
extern int32
ctc_asw_mac_security_get_learn_limit(uint8 lchip, ctc_security_learn_limit_t* p_learn_limit);

/**
 @brief  Set configure of storm ctl

 @param[in] lchip    local chip id

 @param[in] stmctl_cfg   configure of storm ctl

 @remark[TMA]
  Storm control can support port base or vlan base refer to ctc_security_storm_ctl_op_t
  can control packets such as:
  \p
  CTC_SECURITY_STORM_CTL_BCAST        : broadcast storm control.
  \p
  CTC_SECURITY_STORM_CTL_KNOWN_MCAST  : known multicast storm control.
  \p
  CTC_SECURITY_STORM_CTL_UNKNOWN_MCAST: unknown multicast storm control.
  \p
  CTC_SECURITY_STORM_CTL_UNKNOWN_UCAST: unknown unicast storm control.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_storm_ctl_set_cfg(uint8 lchip, ctc_security_stmctl_cfg_t* stmctl_cfg);

/**
 @brief  Get configure of storm ctl

 @param[in] lchip    local chip id

 @param[in|out] stmctl_cfg  configure of storm ctl

 @remark[TMA]
  Get storm contrl configure of type and mode.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_storm_ctl_get_cfg(uint8 lchip, ctc_security_stmctl_cfg_t* stmctl_cfg);

/**
 @brief  Set global configure of storm ctl

 @param[in] lchip    local chip id

 @param[in] p_glb_cfg  global configure of storm ctl

 @remark[TMA]
  Set configure ipg.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_storm_ctl_set_global_cfg(uint8 lchip, ctc_security_stmctl_glb_cfg_t* p_glb_cfg);

/**
 @brief  Get global configure of storm ctl

 @param[in] lchip    local chip id

 @param[out] p_glb_cfg  global configure of storm ctl

 @remark[TMA]
  Get configure ipg.

 @return CTC_E_XXX

*/
extern int32
ctc_asw_storm_ctl_get_global_cfg(uint8 lchip, ctc_security_stmctl_glb_cfg_t* p_glb_cfg);

/**
 @brief Configure port based  mac limit

 @param[in] lchip    local chip id

 @param[in] gport       global port

 @param[in] action      refer to ctc_maclimit_action_t

 @remark[TMA]
       The API configure mac limit on a gport.
       When the function enabled on gport, the packet received on port will do action as enum ctc_maclimit_action_t.
       \p
       action type:
       \p
              CTC_MACLIMIT_ACTION_FWD:          packet will forwarding but no learning mac if reach mac learning limitation.
              \p
              CTC_MACLIMIT_ACTION_DISCARD:      packet will discard and no learning mac if reach mac learning limitation.
              \p
              CTC_MACLIMIT_ACTION_TOCPU:        packet will discard and no learning, redirect to cpu if reach mac learning limitation.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_mac_security_set_port_mac_limit(uint8 lchip, uint32 gport, ctc_maclimit_action_t action);

/**
 @brief Get the configure of port based  mac limit

 @param[in] lchip    local chip id

 @param[in] gport       global port

 @param[out] action      refer to ctc_maclimit_action_t

 @remark[TMA]
        Get info about action of mac limit based on port function on this gport.
 @return CTC_E_XXX
*/
extern int32
ctc_asw_mac_security_get_port_mac_limit(uint8 lchip, uint32 gport, ctc_maclimit_action_t* action);

#ifdef __cplusplus
}
#endif

#endif

